package cn.dy.sbo.web.sys;

import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import cn.dy.sbo.core.UserManager;
import cn.dy.sbo.model.User;
import com.opensymphony.xwork2.ActionSupport;

@Namespace("/sys")
public class ManageAction extends ActionSupport
{
    private static final long serialVersionUID = 8683878162525847072L;

    // -- 页面属性 --//

    private Long              id;                                     // 全局Id

    private Page<User>        page             = new Page<User>(10);  // 每页10条记录

    private User              user;                                   // 定义用户

    private UserManager       userManager;

    /**
     * 获得某个项目下的用户列表,可按用户名和权限等级查询
     * 
     * @since 2011-11-8
     * @see cn.common.lib.springside.web.CrudActionSupport#list()
     */
    public String list() throws Exception
    {
        return SUCCESS;
    }

    /**
     * 进入保存用户页面
     * 
     * @since 2011-11-10
     * @see cn.common.lib.springside.web.CrudActionSupport#input()
     */
    @Override
    public String input() throws Exception
    {
        return INPUT;
    }

    /**
     * 保存用户信息
     * 
     * @since 2011-11-8
     * @see cn.common.lib.springside.web.CrudActionSupport#save()
     */
    public String save()
    {
        return "reload";
    }

    /**
     * 删除用户
     * 
     * @since 2011-11-9
     * @see cn.common.lib.springside.web.CrudActionSupport#delete()
     */
    public String delete() throws Exception
    {
        return "reload";
    }


    protected void prepareModel() throws Exception
    {
        if (null != id)
        {
            user = userManager.get(id);
        }
        else
        {
            user = new User();
        }
    }

    @Autowired
    public void setUserManager(UserManager userManager)
    {
        this.userManager = userManager;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public User getModel()
    {
        return user;
    }

    public Page<User> getPage()
    {
        return page;
    }

    public User getUser()
    {
        return user;
    }

    public void setUser(User user)
    {
        this.user = user;
    }
}